package cn.tedu.file;

import java.io.*;

/*本类用于练习字符输出流Writer*/
public class TestOut2 {
    public static void main(String[] args) {
        //method1();//用于测试普通字符输出流
        method2();//用于测试普通字符输出流
    }

    //本方法用于测试高效字符输出流BufferedWriter
    private static void method2() {
        BufferedWriter out = null;
        try {
            //创建字符输出流对象--覆盖输出
//            out = new BufferedWriter(new FileWriter(new File("D:\\ready\\1.txt")));
//            out = new BufferedWriter(new FileWriter("D:\\ready\\1.txt"));
            //创建字符输出流对象--追加输出
//            out = new BufferedWriter(new FileWriter(new File("D:\\ready\\1.txt"), true));
            out = new BufferedWriter(new FileWriter("D:\\ready\\1.txt", true));
            out.write(45);
            out.write(45);
            out.write(45);
            out.write(56749);
            out.write(65535);
            out.write(65535);
            out.write(65535);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    //本方法用于测试普通字符输出流FileWriter
    private static void method1() {
        FileWriter out = null;
        try {
            //创建字符输出流对象--覆盖对象
//            out = new FileWriter(new File("D:\\ready\\1.txt"));
//            out = new FileWriter("D:\\ready\\1.txt");
            //创建字符输出流对象--追加对象
            out = new FileWriter(new File("D:\\ready\\1.txt"), true);
//            out = new FileWriter("D:\\ready\\1.txt",true);
            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
